Add _finish_when_safe to work around DBD::Pg race condition#89
Merged
kraih merged 1 commit intomojolicious:mainfrom Sep 29, 2025
Merged
Add _finish_when_safe to work around DBD::Pg race condition#89kraih merged 1 commit intomojolicious:mainfrom
kraih merged 1 commit intomojolicious:mainfrom
Conversation
Member
|
I've fixed the tests, please rebase on main. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a private method
_finish_when_safeinMojo::Pg::Database, used byMojo::Pg::Resultsinstead of callingfinishdirectly on DBI statement handles.Motivation
There is a race condition in
DBD::Pgwhich causes in-progress statement handles to be finished inappropriately when old statement handles are finished during an async DB query. This issue was previously concealed by a memory leak inMojo::Promisewhich kept affected objects alive more or less indefinitely. Now that the leak is fixed, thisDBD::Pgbug can cause async DB operations in close proximity to fail.This change works around the problem by postponing finish operations if an async query is in progress. Most of the time there will be no such query in progress, and the handle is finished immediately. Where unsafe, a temporary array is created to hold any incoming statement handles, and the contents of this array (if any) are finished when the async operation completes.
References
DBD::Pgissue: Statement handle DESTROY slurps pending async queries bucardo/dbdpg#105